/*
 * ThreadSafetyQueue.h
 *
 *  Created on: Nov 16, 2012
 *      Author: lucas
 */

#ifndef THREADSAFETYQUEUE_H_
#define THREADSAFETYQUEUE_H_
#include <deque>
#include "Mutex.h"
#include "Lock.h"

template <typename T>
class ThreadSafetyQueue {
private:
	std::deque<T> queue;
	Mutex m;
public:
	ThreadSafetyQueue() {}
	void push(const T& data) {
		Lock l(m);
		queue.push_back(data);
	}

	T pop() {
		T ret;
		Lock l(m);
		ret = queue.front();
		queue.pop_front();
		return ret;
	}

	bool empty() {
		Lock l(m);
		return queue.empty();
	}
	virtual ~ThreadSafetyQueue() {}
};

#endif /* THREADSAFETYQUEUE_H_ */
